<template>
  <div style="height:100%;width:100%;position:relative;">
      <div class="pagetop" style="text-align:left">
          <table style="width:100%" class="QueryTable">
              <tr>
                  <td>质控仪器</td>
                  <td>
                      <rm-ddl-instrument width="100%" v-model="instrId" defaultflag="1" prgno="LIS541" :clearable="false" @change="instrChange"></rm-ddl-instrument>
                  </td>
                  <td>日期区间</td>
                  <td style="width:280px">
                      <el-date-picker v-model="datetime1" type="date" placeholder="开始日期" value-format="yyyy-MM-dd 00:00:00" size="mini" :clearable="false" style="width:130px"></el-date-picker> -
                      <el-date-picker v-model="datetime2" type="date" placeholder="结束日期" value-format="yyyy-MM-dd 00:00:00" size="mini" :clearable="false" style="width:130px"></el-date-picker>
                  </td>
                  <td style="text-align:center">累计标志</td>
                  <td>
                      <el-radio-group v-model="inuseflag">
                          <el-radio label="All">全部</el-radio>
                          <el-radio label="1">累计</el-radio>
                          <el-radio label="0">不累计</el-radio>
                      </el-radio-group>
                  </td>
                  <td style="text-align:center">审核标志</td>
                  <td>
                      <el-radio-group v-model="checkflag">
                          <el-radio label="All">全部</el-radio>
                          <el-radio label="1">审核</el-radio>
                          <el-radio label="0">不审核</el-radio>
                      </el-radio-group>
                  </td>
                  <td></td>
              </tr>
              <tr>
                  <td>水平</td>
                  <td>
                      <rm-ddl-common datatype="seccode" kindno="QCLEVEL" dataname="水平" v-model="level" width="100%" @change="levelChange"></rm-ddl-common>

                  </td>
                  <td></td>
                  <td></td>
                  <td style="text-align:center">参与画图</td>
                  <td>
                      <el-radio-group v-model="drawflag">
                          <el-radio label="All">全部</el-radio>
                          <el-radio label="1">画图</el-radio>
                          <el-radio label="0">不画图</el-radio>
                      </el-radio-group>
                  </td>
                  <td style="text-align:center">失控标志</td>
                  <td>
                      <el-radio-group v-model="controlstatus">
                          <el-radio label="All">全部</el-radio>
                          <el-radio label="1">在控</el-radio>
                          <el-radio label="0">失控</el-radio>
                          <el-radio label="">未判定</el-radio>
                      </el-radio-group>
                  </td>
                  <td></td>
              </tr>
              <tr>
                  <td colspan="9">
                      <el-button @click="QueryData()" type="primary">查询</el-button>
                      <el-button @click="PrintTable()">打印</el-button>
                      <el-button @click="btnExport()">导出</el-button>
                  </td>
              </tr>

          </table>
      </div>
      <div class="pagecenter">
          <vxe-table show-overflow ref="xTable1" height="auto" :data.sync="tableData" border size="mini" show-header-overflow highlight-current-row highlight-hover-row show-footer resizable stripe>
              <vxe-table-column field="itemcode_en" title="代号" width="80px" header-align="center"></vxe-table-column>
              <vxe-table-column field="rpt_itemname" title="项目" width="160px" header-align="center"></vxe-table-column>
              <vxe-table-column field="batchno" title="批号" width="100px" header-align="center"></vxe-table-column>
              <vxe-table-column field="qclevel" title="水平" width="60px" header-align="center" align="center"></vxe-table-column>
              <vxe-table-column field="qccnt" title="测试数" width="80px" header-align="center" align="center"></vxe-table-column>
              <vxe-table-column field="ivtagvalue" title="靶值  x̅" width="100px" header-align="center" align="center"></vxe-table-column>
              <vxe-table-column field="ivsd" title="标准差SD" width="100px" header-align="center" align="center"></vxe-table-column>
              <vxe-table-column field="ivcv" title="变异系数CV" width="100px" header-align="center" align="center"></vxe-table-column>
              <vxe-table-column field="val" title="当前均值" width="100px" header-align="center" align="center"></vxe-table-column>
              <vxe-table-column field="sd" title="当前SD" width="100px" header-align="center" align="center"></vxe-table-column>
              <vxe-table-column field="cv" title="当前CV" width="100px" header-align="center" align="center"></vxe-table-column>
          </vxe-table>
      </div>
  </div>
</template>

<script type="text/javascript">
import XEUtils from "xe-utils"; //引入工具类
export default {
  name: "LIS541",
  data() {
      return {
          instrId: "",
          level: "",
          datetime1: "", //开始日期
          datetime2: "", //结束日期
          inuseflag: "All", //累计标志
          checkflag: "All", //审核标志
          drawflag: "All", //画图标志
          controlstatus: "All", //失控标志
          tableData: [],
          tableColumns: [],
          Printstr: "",
          exportTableColLen: 0,
          instrname: "",
          levelname: "",
      };
  },
  created() {
      this.InitPageDate(); //初始化主列表
  },
  mounted() {},
  updated() {},
  methods: {
      //页面初始化加载
      InitPageDate() {
          this.datetime1 = XEUtils.toDateString(new Date(), "yyyy-MM-01 00:00:00"); //起 始结束日期
          this.datetime2 = XEUtils.toDateString(new Date(), "yyyy-MM-dd 00:00:00");
      },
      //表格方法
      currentchangeEvent({ row, column }) {},
      //后台交互方法
      QueryData() {
          var searchParam = {
              level: this.level,
              qcdate1: this.datetime1,
              qcdate2: this.datetime2,
              instrid: this.instrId,
              inuseflag: this.inuseflag,
              checkflag: this.checkflag,
              drawflag: this.drawflag,
              controlstatus: this.controlstatus,
          };
          this.$tool
              .request({
                  url: "LIS/LIS5/LIS541",
                  method: "post",
                  data: {
                      action: "query",
                      ...searchParam,
                  },
              })
              .then((res) => {
                  if (res.errcode == "1") {
                      this.tableData = res.Data;
                      this.Printstr = res.print;
                      if (this.tableData.length > 0) {
                          for (let i = 0; i < this.tableData.length; i++) {
                              if (this.tableData[i].val == 0) {
                                  this.tableData[i].val = "0.00";
                                  this.tableData[i].cv = "0.00";
                              } else this.tableData[i].cv = XEUtils.toFixedString(((this.tableData[i].sd - 0) * 100) / (this.tableData[i].val - 0), 2);
                              this.tableData[i].val = XEUtils.toFixedString(this.tableData[i].val, 2);
                              this.tableData[i].sd = XEUtils.toFixedString(this.tableData[i].sd, 2);
                          }
                      }
                  }
              });
      },
      //打印
      PrintTable() {
          if (typeof jsObj != "undefined") {
              this.$pub.printCustomXml(this.Printstr, "6010", "admin", "LIS541");
              // this.$pub.designCustomXml(this.Printstr,'6010','admin','LIS541');
          } else {
              this.$alert("请使用" + this.$pub.clientname + "打开系统", "错误", {
                  confirmButtonText: "确定",
              });
          }
      },
      instrChange(code, name) {
          this.instrId = code;
          this.instrname= name;
      },
      levelChange(code, name) {
          this.level = code;
          this.levelname = name;
      },
      //导出
      btnExport() {
          let data = this.getExportData();
          let filtertxt = this.getExportFilter();
          this.$pub.exportTableExcelWithData(data, this.exportTableColLen, "质控项目统计.xlsx", filtertxt, "统计查询：");
      },
      // 获取当前导出文件的所有查询条件
      getExportFilter() {
          let filtertxt = "日期区间:" + XEUtils.toDateString(this.datetime1, "yyyy-MM-dd") + "至" + XEUtils.toDateString(this.datetime2, "yyyy-MM-dd") + "; ";
          if(this.instrId) filtertxt += "质控仪器:" + this.instrname + "; ";
          if(this.inuseflag) filtertxt += "累计标志:" + (this.inuseflag == "1" ? "累计" : this.inuseflag == "0" ? "不累计" : "全部") + "; ";
          if(this.checkflag) filtertxt += "审核标志:" + (this.checkflag == "1" ? "审核" : this.checkflag == "0" ? "不审核" : "全部")  + "; ";
          if(this.level) filtertxt += "水平:" + this.levelname + "; ";
          if(this.drawflag) filtertxt += "参与画图:" + (this.drawflag == "1" ? "画图" : this.drawflag == "0" ? "不画图" : "全部")  + "; ";
          filtertxt += "失控标志:" +(this.controlstatus == "1" ? "在控" : this.controlstatus == "0" ? "失控" : this.controlstatus == "All" ? "全部" : "未判定")  + "; ";
          return filtertxt;
      },
      getExportData() {
          var allcolumns = this.$refs.xTable1.getColumns();
          var tableColumn = [];
          for (let i = 0; i < allcolumns.length; i++) {
              tableColumn.push({ field: allcolumns[i].property, title: allcolumns[i].title });
          }
          let datas = this.tableData;
          this.exportTableColLen = tableColumn.length;
          let columns = tableColumn.filter((item) => item.field);
          let headers = [columns.map((item) => item.title)];
          return headers.concat(
              datas.map((row) => {
                  return columns.map((column) => {
                      return row[column.field];
                  });
              })
          );
      },
      toBuffer(wbout) {
          let buf = new ArrayBuffer(wbout.length);
          let view = new Uint8Array(buf);
          for (let index = 0; index !== wbout.length; ++index) view[index] = wbout.charCodeAt(index) & 0xff;
          return buf;
      },
  },
};
</script>


<style scoped>
.pagetop {
  width: 100%;
  height: 108px;
  display: -webkit-box;
  -webkit-box-pack: left;
  -webkit-box-align: center;
  border: 1px solid #ccc;
  position: absolute;
  z-index: 99;
}
.pagecenter {
  position: absolute;
  top: 112px;
  width: 100%;
  left: 0;
  bottom: 0px;
  overflow: auto;
}
.middle-right {
  position: absolute;
  height: 100%;
  right: 0px;
  bottom: 0px;
  overflow: visible;
}
.middle-center {
  position: absolute;
  height: 100%;
  overflow: auto;
}

table tr td:nth-child(1) {
  width: 80px;
}
.QueryTable tr td:nth-child(odd) {
  text-align: right;
  white-space: nowrap;
  font-size: 12px;
  width: 80px;
  font-weight: bold;
}
</style>